package com.blb.ssm.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.blb.ssm.service.DepotService;

@Controller
@RequestMapping("/depot")
public class DepotController {
	
	@Autowired
	private DepotService depotService;
	
	
	@RequestMapping("")
	public String showDepot(){
		return "depot";
	}
	
	@ResponseBody
	@RequestMapping("/all")
	public Map<String,Object> getDepotList(String gcode,String gname,int page,int limit,String val)throws Exception{
		//设置一个标识区分是哪个仓库查询
		int a=0;
		return test(gcode,gname,page,limit,val,a);
	}
	
	@ResponseBody
	@RequestMapping("/one")
	public Map<String,Object> getDepot1(String gcode,String gname,int page,int limit,String val){
		//设置一个标识区分是哪个仓库查询
		int a=1;
		return test(gcode,gname,page,limit,val,a);
	}
	
	@ResponseBody
	@RequestMapping("/two")
	public Map<String,Object> getDepot2(String gcode,String gname,int page,int limit,String val){
		//设置一个标识区分是哪个仓库查询
		int a=2;
		return test(gcode,gname,page,limit,val,a);
	}
		
	public Map<String,Object> test(String gcode,String gname,int page,int limit,String val,int a){
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("code", 0);
		map.put("msg", "");
		if("明细".equals(val)){
			List<Map<String,Object>> list=depotService.getAllList(gcode,gname,page,limit,a);
			int count=depotService.getCount(gcode,gname,a);
			map.put("count", count);
			map.put("data", list);
		}else if("汇总".equals(val)){
			List<Map<String,Object>> list1=depotService.getAllList2(gcode,gname,page,limit,a);
			int count1=depotService.getCount12(gcode,gname,a);
			map.put("count", count1);
			map.put("data", list1);
		}
		return map;
	}
}
